#!/usr/bin/python
# -*- coding: UTF-8 -*-
# ========================
# @Time  : 2020/2/11 15:26
# @Author: Mecell
# @File  : com_function.py
# ========================

import string
import time
import arrow
import random
import datetime
from collections import namedtuple
import arrow



def generate_random_no(n):
    """随机生成N位数的随机数"""
    list_digits = random.sample(string.digits,n)
    str_digits = "".join(list_digits)
    return str_digits

def select_random_item(data_list):
    """随机抽取列表中的一个数据"""
    one_day = random.sample(data_list, 1)
    return one_day[0]

def generate_namedtuple(fields_list,data_tuple):
    """生成命名元组组成的列表"""
    namedtuple_list = []
    fields_namedtuple = namedtuple("fields", fields_list)
    for data_str in data_tuple:
        namedtuple_list.append(fields_namedtuple(*data_str))
    return namedtuple_list

def day_after(n):
    """当前天的后n天"""
    return str(datetime.date.today() + datetime.timedelta(+n))

def today_before_after_month(n): # n为正数则是后n个月，n为负数则是前n个月
    """当前日期前后n个月的日期"""
    # now_date = arrow.now().date()
    return arrow.now().shift(months=n).date()

def time_after(time,n):
    """指定时间的后n天"""
    return str(time + datetime.timedelta(+n))

def current_time():
    """获取当前系统时间"""
    return time.strftime("%Y-%m-%d %H:%M:%S")

def month_after(time,m,n):
    """获取指定时间的前、后几个月或前后几天"""
    return arrow.get(time, "YYYY-MM-DD").shift(months=m, days=n).date()



if __name__ == '__main__':
    # print(generate_random_no(5))
    # print(select_random_day())
    # xx = day_before(30)
    # print(xx)
    print(current_time())









